package logic

import (
	"context"
	"library/libraryrpc/libraryrpc"

	"library/api/internal/svc"
	"library/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type InformationAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInformationAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InformationAddLogic {
	return &InformationAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InformationAddLogic) InformationAdd(req *types.InformationAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.LibraryRpc.InformationAdd(l.ctx, &libraryrpc.InformationAddRequest{
		Title:  req.Title,
		Desc:   req.Desc,
		Number: req.Number,
		UserId: req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    200,
		}, nil
	}
	return &types.Response{
		Message: "资料添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
